var vm = new Vue({
    el: "section",
    data: {
        userid: "",
        userID: "",
        userInfo: {},
        isMyFriend: false,
        // 组件
        // 输入框弹窗
        show: false,
        editnote: ''
    },
    computed: {
        myStringByteCount: function() {  
            return this.getByteCount1(this.myString);  
        } 
    },
    methods: {
        // 好友列表
        toSend(){
            let href = `../chat/index.html?userID=${this.userID}&note=${encodeURIComponent(this.userInfo.note)}`
            if(this.userInfo.isMyFriend){
                window.location.href= href
            }else{
                this.$toast({
                    message: "对比不是你的好友",
                    forbidClick: true
                })
            }
        },
        addFriend(){
            let loading1 = this.$toast.loading({
                message: '加载中...',
                forbidClick: true,
                loadingType: 'circular',
                duration: 10000
              });
            let url = `https://fc-mp-e8e2bde5-0c0c-4622-87b5-66f8b08c3856.next.bspapp.com/getArticleList1.0`
            let method = `addFriend_98DV45fb8J4Y8KA6`
            let data = {
                userid: this.userid,
                userID: this.userID
            }
            axios.post(`${url}/${method}`, data)
            .then(res=>{
                loading1.clear()
                if(res.data.code == 0){
                    if(res.data.data.code == -1){
                        this.$toast({
                            message: '不可重复发送申请！',
                            forbidClick: true
                        })
                    }else if(res.data.data.code == 0){
                        this.$toast({
                            message: '已发送好友申请',
                            forbidClick: true
                        })
                    }
                }else{
                    this.$toast({
                        message: `服务出错[${res.data.code}]`,
                        forbid: true
                    })
                }
            })


        },
        // 修改备注
        note(){
            if(!this.userInfo.isMyFriend){
                this.$toast({
                    message: '请先添加好友',
                    forbidClick: true
                })
                return
            }
            this.show = true
        },
        // 备注_确认
        confirm(){
            if(!this.userInfo.isMyFriend){
                this.$toast({
                    message: '请先添加好友',
                    forbidClick: true
                })
                return
            }
            let loading1 = this.$toast.loading({
                message: "加载中...",
                forbidClick: true,
                duration: 10000,

            })
            console.log("确认")
            if((/^\s*$/.test(this.editnote)) && (this.userInfo.note == this.userInfo.name)){//不执行
                console.log("不执行")
                setTimeout(()=>{
                    loading1.clear()
                    this.editnote = ""
                    this.$toast.success({
                        message: "成功！",
                        forbidClick: true,
                        duration: 1500,
                    })
                }, 1500)
            }else{//执行
                console.log("执行")
                if((/^\s*$/.test(this.editnote))){
                    this.editnote = ""
                }
                let url = `https://fc-mp-e8e2bde5-0c0c-4622-87b5-66f8b08c3856.next.bspapp.com/getArticleList1.0`
                let method = `editFriendNote_86V756rh4b6J4K86YT`
                let data = {
                    userid: this.userid,
                    userID: this.userID,
                    note: this.editnote.slice(0, 16)
                }
                axios.post(`${url}/${method}`, data)
                .then(res=>{
                    loading1.clear()
                    if(res.data.code == 0){
                        this.$toast.success({
                            message: "成功！",
                            forbidClick: true,
                            duration: 1500,
                        })
                        if((/^\s*$/.test(this.editnote))){
                            this.userInfo.note = this.userInfo.name
                        }else{
                            this.userInfo.note = this.editnote
                        }
                        
                    }else{
                        this.$toast({
                            message: `服务出错[${res.data.code}]`,
                            forbidClick: true,
                        })
                    }
                    this.editnote = ""
                })
            }
        },
        // 备注_取消
        cancel(){
            console.log("取消")
            this.editnote = ""
        },
    },
    mounted() {
        let loading1 = this.$toast({
            message: '加载中...',
            duration: 10000,
            forbidClick: true
        })
        let params1 = location.search.substring(1)
        this.userID = params1.split('=')[1]
        // 获取消息
        let userInfo = localStorage.getItem('XGB-user')
        this.userid = JSON.parse(userInfo).id
        // let userMsg = encodeURIComponent(this.userMsg)

        let url = `https://fc-mp-e8e2bde5-0c0c-4622-87b5-66f8b08c3856.next.bspapp.com/getArticleList1.0`
        let method = `getUserInformation_D8v1SVB18sv14681RV`
        let data = {
            userid: this.userid,
            userID: this.userID
        }
        axios.post(`${url}/${method}`, data)
        .then(res=>{
            loading1.clear()
            
            if(res.data.code === 0){
                this.userInfo = res.data.data
                this.userInfo.province = res.data.data.area.province
                this.userInfo.city = res.data.data.area.city
                console.log(this.userInfo)
            }else{
                this.$toast({
                    message: `服务出错[${res.data.code}]`,
                    forbidClick: true
                })
            }
            // 
            setTimeout(()=>{
                let lis = document.querySelectorAll("li:not(:first-child)")
                for(let i=0;i<lis.length; i++){
                    $(`li:nth-child(${i+2})`).on('touchstart', function(){
                        $(`li:nth-child(${i+2})`).css('background', '#c3c3c352')
                    })
                    $(`li:nth-child(${i+2})`).on('touchend', function(){
                        $(`li:nth-child(${i+2})`).css('background', '#fff')
                    })
                }
            }, 100)
            // 



        })
    }
})